Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

adjusting datagrid column width

已查看 0 次
跳至第一个未读帖子

Nedu N

未读,
2004年1月19日 13:35:482004/1/19
收件人
Hi,
I want to know what are all the ways with which we can precisely control the
width of the datagrid columns. Iam facing problems in controlling the width
of the datagrid columns.

Thanks


Teemu Keiski

未读,
2004年1月19日 14:07:062004/1/19
收件人
Hi,

declaratively

ItemStyle-Width="150px"

would work as well as if you specify it via code (via DataGrid's Columns
collection) but then something like:

DataGrid1.Columns(0).ItemStyle.Width=Unit.Pixel(150)

That's all I can really say without knowing more about your scenario. If
this doesn't help, please provide bit more details.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Nedu N" <ned...@hotmail.com> wrote in message
news:OcDf9sr3...@tk2msftngp13.phx.gbl...

Jeffrey Tan[MSFT]

未读,
2004年1月19日 22:25:562004/1/19
收件人

Hi Nedu,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, you want to get the fully control of the column
width of the web form datagrid control.

==================================================
1). If your column is customized column, you can control it through
ItemStyle in the Html designer:
<asp:TemplateColumn>
<ItemTemplate>
..............
</ItemTemplate>
<ItemStyle Width=50px></ItemStyle>
</asp:TemplateColumn>

2). For auto generated column, you can control it before render(At
runtime), like this:
private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
DataGrid1.Columns[0].ItemStyle.Width=Unit.Pixel(100);
}

Actually, the datagrid control will render as <table> html tag.After
setting its column width, .Net will add "width" attribute to all the <td>
in that column.(You can determine this through view html source in page)

Note: If your column's width is very small, IE will wrap the text in all
the cells(<td> tags) in that column, so the whole datagrid height
increased. But IE will not wrap a single word, so there are a minimal size
for the width to take effect.(The minimal size is the longest word in that
column)
For example, if I set a column width to 5px, which is smaller than most of
the words, then the text in <td> will like this:
//First <td>
Public
Relations
Manager

//Second <td>
Sales
Representative

//Third <td>
Operations
Manager

So this column's width will be the width of word "Representative".(Because
it is the longest word in that column). If you view the source, you will
see that all the <td> still have width attribute with value 10px. So this
is the default behavior of IE browser not Asp.net.

Hope this make sense to you.
=================================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Hope you have a nice experience in Microsoft Newsgroup!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

0 个新帖子